package cn.pfund.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.pfund.entity.Navigation;
import cn.pfund.service.NavigationService;
import cn.pfund.dao.NavigationDao;
import cn.pfund.util.Pagination;
import cn.pfund.util.ParamBean;
import cn.pfund.util.QueryCondition;

@Service("navigationService")
public class NavigationServiceImpl extends BaseServiceImpl implements NavigationService {
	@Resource(name="navigationDao")
    private NavigationDao navigationDao;
    
    @Transactional(readOnly = true)
	public Pagination<Navigation> getPagination(ParamBean paramBean) {
		List<QueryCondition> queryConditions = new ArrayList<QueryCondition>();
		if (StringUtils.isNotBlank(paramBean.getKeyword())) {
			queryConditions.add(new QueryCondition(paramBean.getField(), QueryCondition.LK, paramBean.getKeyword()));
		}
		String orderBy = "order by orders asc";
		Pagination<Navigation> pagination = (Pagination<Navigation>)getPagination(Navigation.class, queryConditions, orderBy, paramBean.getPage(), paramBean.getPageSize());
		pagination.setPageHtml(paramBean.getUrl());
		return pagination;
	}

    @Transactional(readOnly = true)
	public List<Navigation> getAllNavigation() {
    	String orderBy = "order by orders asc";
		return get(Navigation.class, null, orderBy);
	}
}
